<!DOCTYPE html>
<html>

{include file='public/header'}

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="javascript:void(0)">首页</a>
            <a href="javascript:void(0)">账号管理</a>
            <a><cite>小程序管理</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" id="reload" title="刷新">
            <i class="layui-icon" style="line-height:30px"><i class="iconfont">&#xe6aa;</i></i>
        </a>
    </div>
    <div class="x-body">
        <form class="layui-form layui-row" style="margin-top:15px;margin-bottom: 10px;">

            <div class="layui-inline">
                <label class="layui-form-label w-auto">投放平台：</label>
                <div id="pMedia" style="width:100%;flex:1"></div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label w-auto">小程序名称：</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" placeholder="请输入小程序名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline" style="margin-left:10px">
                <button class="layui-btn" lay-submit lay-filter="searchList">搜索</button>
                <button type="reset" id="resetList" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </form>

        <table id="official_accounts" lay-filter="official_accounts"></table>
    </div>
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="add">添加小程序</button>
        </div>
    </script>
    <script type="text/html" id="tbBar">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script>
        let params = {
            elem: '#official_accounts'
            , toolbar: '#toolbarDemo'
            , url: '/admin/applet/list' //数据接口
            , id: 'official_accounts'
            , limit:15
            ,page:true
            , cols: [[ //表头
                { field: 'id', title: 'ID', width: 80, sort: true, align:'center', width:90}
                , {title: '平台类型', templet: function (d) {
                        if (d.type == 1) {
                            return '微信小程序';
                        } else if (d.type == 2) {
                            return '抖音小程序';
                        } else if (d.type == 3) {
                            return '快手小程序';
                        }
                    }, align:'center', width:130
                },
                {title: '公司主体', templet: function (d) {
                        if (d.company_entity_id == 1) {
                            return '比翼鸟公司主体';
                        } else if (d.company_entity_id == 3) {
                            return '南宁源誉网络科技主体';
                        }
                    }, align:'center', width:130
                }
                , { field: 'name', title: '小程序名称', align:'center', width:150}
                , { field: 'app_id', title: '小程序appid', align:'center', width:200}
                , { field: 'app_secret', title: '小程序appsecret', align:'center'}
                , { field: 'origin_id', title: '小程序原始ID', align:'center', width:180}
                , {title: 'iOS支付', templet: function (d) {
                        return d.ios_pay_switch == 1 ? '开启' : '关闭'
                    }, align:'center', width:100
                }
                , {title: '分享', templet: function (d) {
                        return d.share_switch == 1 ? '开启' : '关闭'
                    }, align:'center', width:100
                }
                , {title: '活动', templet: function (d) {
                        return d.activity_pay_show == 1 ? '开启' : '关闭'
                    }, align:'center', width:100
                }
                , {title: '虚拟支付', templet: function (d) {
                        return d.virtual_pay_switch == 1 ? '开启' : '关闭'
                    }, align:'center', width:100
                }
                , {title: '状态', templet: function (d) {
                        return d.status == 1 ? '开启' : '关闭'
                    }, align:'center', width:100
                }
                , { toolbar: '#tbBar', title: '操作', width: 130, align:'center' }
            ]]
        }
        tableList(params)

        layui.use('table', function () {
            var table = layui.table;
            table.on('toolbar(official_accounts)', function (obj) {
                var event = obj.event;
                if (event === 'add') {
                    x_admin_show('添加小程序', './info.html', 650, 600);
                }
            });
            table.on('tool(official_accounts)', function (obj) {
                var event = obj.event;
                if (event === 'del') {
                    DeleteAjax('/admin/applet/delete',{ id: obj.data.id },'official_accounts')
                } else if (event === 'edit') {
                    x_admin_show('编辑小程序', `./info.html?company_id=${obj.data.company_id}&id=${obj.data.id}`, 650, 600);
                }
            });

        });
        
        let selectMedia = {
            url: '/admin/applet/getAppletType',
            selected: [],
            tips: '请选择',
            name: 'type',
            field_id: 'id',
            field_Name: 'name',
            elem: '#pMedia'
        }
        selectN(selectMedia)

    </script>
</body>

</html>